#!/usr/local/bin/python
# -*- coding: gbk -*-
#============================================================
# LOGIREFILE.PY            -- by Dr. ZhuoQing 2021-02-02
#
# Note:
#============================================================

from head import *


#------------------------------------------------------------
logidir = r'f:\logi'

filelist = sort([s for s in os.listdir(logidir) if s.count('-') == 4])

if len(filelist) == 0:
    printf("%s has no LOGI record file.\a"%logidir)
    exit(0)

printf(filelist)
#------------------------------------------------------------
dopfile = tspgetdopfile()
newfile = "%s.mp4"%(os.path.basename(dopfile).split('.')[0])
savefile = os.path.join(logidir, newfile)

#------------------------------------------------------------
if os.path.isfile(savefile):
    printf("The file has already existed .\a")

    id = 0
    while True:
        newfile = "%s-%d.mp4"%(os.path.basename(dopfile).split('.')[0], id)
        savefile = os.path.join(logidir, newfile)
        if not os.path.isfile(savefile):
            break
        id += 1


#------------------------------------------------------------
os.rename(os.path.join(logidir,filelist[-1]), savefile)

printf("%s-->%s\a"%(filelist[-1], newfile))








#------------------------------------------------------------
#        END OF FILE : LOGIREFILE.PY
#============================================================
